# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname='puppet_metadata'
pkgname="ruby-${_gemname}"
pkgver=3.2.0
pkgrel=1
pkgdesc='Data structures for the Puppet Metadata'
arch=('any')
url="https://github.com/voxpupuli/${_gemname}"
license=('Apache')
depends=('ruby' 'ruby-metadata-json-lint' 'ruby-semantic_puppet')
makedepends=('ruby-rdoc' 'ruby-rake' 'ruby-rspec' 'ruby-rspec-its')
options=('!emptydirs')
source=("${url}/archive/${pkgver}/${_gemname}-${pkgver}.tar.gz")
sha512sums=('fd6fcfc51d0960940b109e3480ad1b9894ffa76a7c6c73da8f806c8de58736e46eb6d74968442e3885c31367d2366448abe589af876a9eac95acd51b0567c438')

prepare() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  # allow latest dependencies
  sed --in-place 's|~>|>=|g' "${_gemname}.gemspec"

  # drop development deps, they only cause dependency issues and aren't required
  sed --in-place '/add_development_dependency/d' "${_gemname}.gemspec"
}

build() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  rake
}

package() {
cd "${srcdir}/${_gemname}-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}/"

  install -Dm 644 README.md HISTORY.md CHANGELOG.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
}
